package com.ruoyi.common.order.strategy.impl;

import com.ruoyi.common.order.strategy.AbstractOrderNumberStrategy;
import com.ruoyi.sale.domain.SaleorderOrder;
import com.ruoyi.sale.mapper.SaleorderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 销售订单
 */
@Component
public class SaleOrderStrategyImpl extends AbstractOrderNumberStrategy {

    private static final String FLAG = "3";

    /**
     * 获取标识
     * @return 标识
     */
    @Override
    public String identity() {
        return FLAG;
    }

    /**
     * 构建查询参数
     * @param date 日期字符串
     * @param companyId 公司ID
     * @return 结果
     */
    @Override
    protected Map<String, Object> buildParams(String date, Long companyId) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("saleorderDate", date);
        params.put("deptId", companyId);
        return params;
    }

    @Autowired
    private SaleorderMapper saleorderMapper;
    /**
     * 查询依旧订单
     * @param params 查询参数
     * @return
     */
    @Override
    protected String queryLastOrderNumber(Map<String, Object> params) {
        List<SaleorderOrder> list = saleorderMapper.selectSaleorderByDate(params);
        return list.isEmpty() ? null : list.get(0).getSaleorderNum();
    }
}
